home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ KopyRong (K) 1987. ALL RIGHTS REVERSED. */
- /* */
- /* */
- /* This module was originally written by Wynn Wagner III */
- /* with significant changes made by Vince Perriello and Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm "Main" Module: Terminal Emulation and */
- /* File Transfer dispatching */
- /* */
- /* */
- /* This software package is being distributed WITH FULL SOURCE CODE */
- /* with the following conditions: 1) If anything awful happens */
- /* because you use it (or don't use it), you accept full */
- /* responsibility; 2) you don't start making tons of voice calls to */
- /* the authors to complain or make suggestions about enhancements, */
- /* useful or otherwise; 3) you do not reuse this code in commercial */
- /* products without specific permission to do so from the authors; */
- /* 4) If you find any problems you send fixes to the authors for */
- /* inclusion in updates; 5) You find some way to express your */
- /* appreciation for this method of distribution, either by writing */
- /* code or application notes, or just sending along a "Thank You" */
- /* message. */
- /* */
- /* There is copyrighted code in this product. We either wrote it */
- /* ourselves or got permission to use it. Please don't force us to */
- /* pay a lawyer -- have some respect for our motives and don't abuse */
- /* this "license". */
- /* */
- /* */
- /*--------------------------------------------------------------------------*/
-
-
- #include <stdio.h>
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include "com.h"
- #include "xfer.h"
- #include "keybd.h"
-
- struct pointers ctl;
-
- struct baud_str btypes[] = {
- { "300", BAUD_300 },
- { "1200", BAUD_1200 },
- { "2400", BAUD_2400 },
- { "4800", BAUD_4800 },
- { "9600", BAUD_9600 },
- { "19200", BAUD_19200 },
- { NULL, 0 }
- };
-
- int baud,cur_baud,locate_x,locate_y,port_ptr;
-
- int share = 0; /* if 1, don't uninit FOSSIL */
- int boss_net = 0;
- int boss_node = 0;
- int un_attended = 0;
- int command_line_un;
- int overwrite = 0;
- int redo_dynam = 0;
- int fullscreen = 1;
- int BBStimeout = 2000;
- int loglevel = 10;
- extern int remote_net, remote_node;
- extern struct _node nodedes; /* desc. of node */
- extern int caller;
- extern int noforce;
-
- char *BBSopt = NULL; /* BBS command options */
- char *BBSbanner = NULL; /* BBS banner */
- char *BBSreader = NULL; /* Message reader */
- char *BOSSphone = NULL; /* Phone number for boss */
-
- char *BINKpath = "";
-
- char junk[100];
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- int k;
- int c;
- int done;
- long t1;
- char *envptr,*getenv(),*malloc();
- FILE *logfile = NULL; /* log file stream descriptor */
- char prot;
- int err;
- int mail_only = 0; /* if 1, do mail and exit */
- int bnet, bnode;
- extern long timerset();
- extern char *receive_file();
-
- envptr = getenv("BINKLEY"); /* get path from environment */
- if ((envptr != NULL) /* If there was one, and */
- && (!dexists("Binkley.Cfg"))) /* No BINKLEY.CFG locally, */
- {
- BINKpath = malloc(strlen(envptr) + 1); /* make room for new */
- strcpy(BINKpath,envptr); /* use BINKLEY as our path */
- }
-
- signal (SIGINT, SIG_IGN);
- tzset();
-
- ctl.handshake_mask = USE_XON|USE_CTS;
- ctl.carrier_mask = 0x80;
- ctl.hold_area = ctl.filepath = ctl.net_info = NULL;
- ctl.avail_list = ctl.request_list = ctl.freq_about = NULL;
- ctl.predial = ctl.postdial = ctl.m_init = NULL;
- ctl.matrix_mask = TAKE_REQ;
- ctl.system_name = ctl.sysop = NULL;
- ctl.our_zone = 1;
- ctl.max_baud = 0;
-
- b_init();
-
- baud = 2;
- cur_baud = atoi(btypes[baud].str);
- command_line_un = 0;
-
- while (--argc)
- {
- ++argv;
- if (strnicmp (argv[0], "noforce", 7) == 0)
- {
- noforce = 1;
- continue;
- }
- else if (strnicmp(argv[0],"mail",4) == 0)
- {
- ++mail_only;
- continue;
- }
- else if (strnicmp(argv[0],"share",5) == 0)
- {
- ++share;
- continue;
- }
- else if (strnicmp(argv[0],"dynam",5) == 0)
- {
- ++redo_dynam;
- continue;
- }
- else if (strnicmp(argv[0],"unattended",10) == 0)
- {
- un_attended = 1;
- command_line_un = 1;
- continue;
- }
- else
- {
- printf("\r\nUnrecognized option: %s\r\n",argv[0]);
- exit(1);
- }
- }
-
- read_sched();
- parse_config();
-
- if (Cominit(port_ptr) != 0x1954)
- {
- cprintf ("I'm sorry, there doesn't appear to be a FOSSIL driver loaded.\r\n");
- cprintf ("BinkleyTerm requires a FOSSIL driver. Please take care of this before\r\n");
- cprintf ("attempting to run BinkleyTerm again.\r\n");
- exit (1);
- }
-
- k = un_attended;
- un_attended = 0;
- set_baud (ctl.max_baud, 0);
- un_attended = k;
- MDM_ENABLE(btypes[baud].rate);
- DTR_ON();
- XON_ENABLE();
- done = 0;
-
- if (mail_only)
- {
- if (fullscreen)
- {
- opening_banner ();
- mailer_banner ();
- }
- un_attended = 1;
- boss_mail(0);
- un_attended = 0;
- done = 1;
- }
- else if (un_attended)
- {
- done = unattended();
- }
- else
- {
- opening_banner ();
- }
-
- while (!done)
- {
- c = -1;
- if (CHAR_AVAIL())
- {
- c = MODEM_IN();
- WRITE_ANSI(c);
- if (logfile != NULL)
- {
- fwrite(&c,1,1,logfile);
- }
- }
- if (KEYPRESS())
- {
- c = 0;
- k = FOSSIL_CHAR();
- switch (k)
- {
- case ALTX:
- if (logfile != NULL)
- fclose(logfile);
- done = 1;
- break;
-
- case ALTH:
- t1 = timerset (300);
- while (CARRIER)
- if (timeup(t1))
- {
- scr_printf ("\r\nUnable to force carrier drop by dropping DTR!\r\n");
- break;
- }
- else
- {
- DTR_OFF();
- }
- DTR_ON();
- break;
-
- case ALTY:
- scr_printf("\r\nBinkleyTerm now in MAILER mode\r\n");
- boss_mail(1);
- scr_printf("\r\nBinkleyTerm now in MANUAL mode\r\n");
- break;
-
- case ALTL:
- if (logfile != NULL)
- {
- fclose(logfile);
- logfile = NULL;
- scr_printf("\r\nLog file closed.\r\n");
- break;
- }
- /* else */
- scr_printf ("\r\nLog file name: ");
- fgets (junk, 100, stdin);
- if ((k = strlen(junk)) > 2)
- {
- junk[--k] = '\0'; /* no '\n' */
- logfile = fopen(junk,"ab");
- if (logfile == NULL)
- scr_printf("\r\nCould not open specified logfile.\r\n");
- }
- break;
-
- case ALTD:
- scr_printf ("\r\nPlease enter a phone (or net/node) number: ");
- fgets (junk, 100, stdin);
- if ((k = strlen(junk)) < 3)
- break;
- junk[--k] = '\0'; /* no '\n' */
- if (strchr(junk,'/') != NULL)
- {
- if (!nodeproc(junk))
- break;
- }
- else
- {
- strcpy (nodedes.phone, junk);
- }
- caller = 0;
- try_2_connect(nodedes.phone); /* try to connect */
- break;
-
- case ALTM:
- scr_printf ("\r\nPlease enter a net/node number: ");
- fgets (junk, 100, stdin);
- if ((k = strlen(junk)) < 3)
- break;
- junk[--k] = '\0'; /* no '\n' */
- if (sscanf (junk, "%d/%d", &bnet, &bnode) == 2)
- {
- if (bnet >=0 && bnode >= 0)
- {
- scr_printf("\r\nBinkleyTerm now in MAILER mode\r\n");
- do_mail (bnet, bnode);
- scr_printf("\r\nBinkleyTerm now in MANUAL mode\r\n");
- break;
- }
- }
- cprintf ("\r\nCannot get net/node from '%s'\r\n", junk);
- break;
-
- case ALTB:
- ++baud;
- if (btypes[baud].str == NULL)
- baud = 0;
- MDM_ENABLE(btypes[baud].rate);
- cur_baud = atoi(btypes[baud].str);
- scr_printf ("\r\nBinkleyTerm now communicating at ");
- scr_printf (btypes[baud].str);
- scr_printf (" baud.\r\n");
- break;
-
- case ALTP:
- port_ptr = !port_ptr;
- MDM_DISABLE();
- Cominit(port_ptr);
- MDM_ENABLE(btypes[baud].rate);
- DTR_ON();
- scr_printf ("\r\nBinkleyTerm now using COM");
- WRITE_ANSI (port_ptr + '1');
- scr_printf (":\r\n");
- XON_ENABLE();
- break;
-
- case ALTU:
- done = unattended();
- break;
-
- case PGUP:
- XON_DISABLE();
- scr_printf("\r\nBinkleyTerm is ready to SEND a file...\r\n");
- scr_printf("Which Protocol do you want BinkleyTerm to use?\r\n");
- scr_printf("Z)modem Y)modem S)EAlink T)elink X)modem\r\n");
- scr_printf("OK....Choose! ");
- fgets (junk, 100, stdin);
- prot = toupper (junk[0]);
- if ((prot != 'X') && (prot != 'Y')
- && (prot != 'S') && (prot != 'Z')
- && (prot != 'T'))
- {
- scr_printf ("Sorry. I don't know that protocol, returning to terminal mode.\r\n");
- break;
- }
- scr_printf ("File to be sent? ");
- fgets (junk, 100, stdin);
- junk[strlen(junk) - 1] = '\0';
- err = 1;
- if (prot == 'Z')
- {
- Send_Zmodem(junk,NULL,0,0,0);
- Send_Zmodem(NULL,NULL,0,END_BATCH,0);
- XON_ENABLE();
- break;
- }
- if (prot == 'T')
- err = xfermdm7(junk);
- if (err) /* 'X','Y','Z' or good MDM7 filename */
- {
- send_file (junk,prot);
- send_file (NULL, prot);
- }
- XON_ENABLE();
- break;
-
- case PGDN:
- XON_DISABLE();
- scr_printf("\r\nBinkleyTerm is ready to RECEIVE a file...\r\n");
- scr_printf("Which Protocol do you want BinkleyTerm to use?\r\n");
- scr_printf("Z)modem Y)modem S)EAlink T)elink X)modem\r\n");
- scr_printf("OK....Choose! ");
- fgets (junk, 100, stdin);
- prot = toupper (junk[0]);
- junk[0] = '\0';
- if ((prot == 'X') || (prot == 'Y'))
- {
- scr_printf ("File to receive? ");
- fgets (junk, 100, stdin);
- junk[strlen(junk) - 1] = '\0';
- receive_file( "", junk, prot);
- XON_ENABLE();
- break;
- }
- if (prot == 'Z')
- {
- get_Zmodem("",NULL);
- XON_ENABLE();
- break;
- }
- if ((prot != 'T') && (prot != 'S'))
- {
- scr_printf ("Sorry. I don't know that protocol, returning to terminal mode.\r\n");
- break;
- }
- else
- {
- err = 1;
- while (err)
- {
- if (prot == 'T')
- err = recvmdm7(junk);
- if (err)
- err = (receive_file( "", junk, prot) != NULL);
- }
- }
- XON_ENABLE();
- break;
-
- case ALTF10:
- main_help();
- break;
-
- default:
- c = k & 0xff;
- if (c != 0)
- while (Com_Tx_NW (c) == 0)
- ;
- else
- ansi_map(k);
- }
- }
- if (c == -1)
- time_release();
- }
- if (command_line_un)
- {
- mdm_init (ctl.m_busy);
- DTR_OFF();
- }
-
- gotoxy (0, 22);
- while (KEYPRESS())
- {
- FOSSIL_CHAR();
- }
- if (!share)
- MDM_DISABLE();
- cprintf ("Thanks for using BinkleyTerm.\033[K\r\nHope to see you again real soon!\033[K\r\n");
- exit (1);
- }
-
- /*--------------------------------------------------------------------------*/
- /* */
- /* ansi_map() -- map function key into an ANSI escape sequence if we have */
- /* one to correspond to the key. The "emulation" is VT100-type, we map the */
- /* arrow keys to the ANSI escape sequences for up, down, right and left, */
- /* and we map the function keys into the VT100 keypad, assuming application */
- /* mode, like Procomm. That is, we take the VT100 keypad, split it in two */
- /* vertically, and use the F-keys to represent the left side, and the */
- /* "shifted" F-keys to represent the right side. */
- /* */
- /* The result, if any, is transmitted to the host. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- char *ansi_seq[] = { /* IBM key Scan code VT100 key */
- "\033OP", /* F1 3b00 PF1 */
- "\033OQ", /* F2 3c00 PF2 */
- "\033Ow", /* F3 3d00 keypad '7' */
- "\033Ox", /* F4 3e00 keypad '8' */
- "\033Ot", /* F5 3f00 keypad '4' */
- "\033Ou", /* F6 4000 keypad '5' */
- "\033Oq", /* F7 4100 keypad '1' */
- "\033Or", /* F8 4200 keypad '2' */
- "\033Op", /* F9 4300 keypad '0' */
- "\033Op", /* F10 4400 keypad '0' */
- "", /* 4500 */
- "", /* 4600 */
- "", /* 4700 */
- "\033[A", /* Up Arrow 4800 Up Arrow */
- "", /* 4900 */
- "", /* 4a00 */
- "\033[D", /* Left Arrow 4b00 Left Arrow */
- "", /* 4c00 */
- "\033[C", /* Right Arrow 4d00 Right Arrow */
- "", /* 4e00 */
- "", /* 4f00 */
- "\033[B", /* Down Arrow 5000 Down Arrow */
- "", /* 5100 */
- "", /* 5200 */
- "", /* 5300 */
- "\033OR", /* Shift-F1 5400 PF3 */
- "\033OS", /* Shift-F2 5500 PF4 */
- "\033Oy", /* Shift-F3 5600 keypad '9' */
- "\033Om", /* Shift-F4 5700 keypad '-' */
- "\033Ov", /* Shift-F5 5800 keypad '6' */
- "\033Ol", /* Shift-F6 5900 keypad ',' */
- "\033Os", /* Shift-F7 5a00 keypad '3' */
- "\033OM", /* Shift-F8 5b00 keypad 'Enter' */
- "\033On", /* Shift-F9 5c00 keypad '.' */
- "\033OM", /* Shift-F10 5d00 keypad 'Enter' */
- ""
- };
-
- ansi_map(ScanVal)
- unsigned ScanVal;
- {
- register KeyCode;
- register char *s,c;
- KeyCode = ScanVal >> 8; /* Isolate to key scan code */
- if ((KeyCode < 0x3b) || (KeyCode > 0x5d))
- return; /* Not in range, give up */
- s = ansi_seq[KeyCode - 0x3b]; /* Index to our sequence */
- while (c = *s++) /* Until the end of string, */
- {
- while (Com_Tx_NW (c) == 0) /* Keep sending those chars */
- ;
- }
- }
-
- opening_banner ()
- {
- scr_printf ("\033[H\033[2J");
- scr_printf (ANNOUNCE);
- if (!un_attended)
- scr_printf ("A Companion Package for communicating with the Opus CBCS\r\n");
- else
- scr_printf ("A Public Domain FidoNet Compatible Mail Utility\r\n");
-
- scr_printf ("Setting COM");
- WRITE_ANSI (port_ptr + '1');
- scr_printf (": to initial speed of ");
- scr_printf (btypes[baud].str);
- scr_printf (" baud. Press Alt-F10 for HELP.\r\n");
- fossil_ver();
- mtask_find();
- }